package it.storm.solution;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 1920. 基于排列构建数组
 * https://leetcode-cn.com/problems/build-array-from-permutation/
 */
public class Solutions_1920 {
    public static void main(String[] args) {
        int[] nums1 = {0, 2, 1, 5, 3, 4};  // output: {0, 1, 2, 4, 5, 3}
        int[] nums2 = {5, 0, 1, 2, 3, 4};  // output: {4, 5, 0, 1, 2, 3}

        List<int[]> inputs = new ArrayList<>();
        inputs.add(nums1);
        inputs.add(nums2);

        for (int[] input : inputs) {
            int[] result = buildArray(input);
            System.out.println(Arrays.toString(result));
        }
    }

    public static int[] buildArray(int[] nums) {
        int len = nums.length;
        int[] res = new int[len];
        for (int i = 0; i < nums.length; i++) {
            res[i] = nums[nums[i]];
        }
        return res;
    }
}
